package com.zhima.controller.plain;

import com.zhima.annotation.MustLogin;
import com.zhima.dto.ZhimaOjPageResult;
import com.zhima.dto.ZhimaOjResult;
import com.zhima.service.OjQuestionAuditService;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhima
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/audit")
public class OjQuestionAuditController {
    @Autowired
    private OjQuestionAuditService ojQuestionAuditService;

    /**
     * 用户分页查询用户提交的审核记录
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public ZhimaOjPageResult pageQueryQuestionAudit(@PathVariable("pageNum") Long pageNum, @PathVariable("pageSize") Long pageSize) {
        return ZhimaOjPageResult.success(ojQuestionAuditService.pageQueryQuestionAudit(UserHolder.get().getId(), pageNum, pageSize, false));
    }

    /**
     * 取消审核指定题目
     *
     * @param questionId
     * @return
     */
    @PostMapping("/cancel/{questionId}")
    public ZhimaOjResult cancelSubmitQuestionAudit(@PathVariable("questionId") Long questionId) {
        // 取消审核
        return success(ojQuestionAuditService.cancelSubmitQuestionAudit(questionId));
    }

    /**
     * 用户提交题目审核
     *
     * @param questionId
     * @return
     */
    @PostMapping("/{questionId}")
    public ZhimaOjResult submitAuditQuestion(@PathVariable("questionId") Long questionId) {
        return success(ojQuestionAuditService.submitAuditQuestion(UserHolder.get().getId(), questionId));
    }

    @GetMapping("/{questionId}")
    @MustLogin
    public ZhimaOjResult queryQuestionDetailById(@PathVariable("questionId") Long questionId) {
        return success(ojQuestionAuditService.queryQuestionDetailById(UserHolder.get().getId(), questionId));
    }
}
